/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kkks.spring_rest.tick.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * 
 */
public class DateHelper {

    public static Date getCurrentDate() {
        Calendar ca = Calendar.getInstance();
        ca.add(Calendar.HOUR, -8);
        return ca.getTime();
    }
    
  public static Date getEarlyDate() throws ParseException{
       
      SimpleDateFormat sp=new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,-1);
      
      return sp.parse(sp.format(cal.getTime()));
  }
  
  public static Date getLaterDate() throws ParseException{
       
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date date=new Date();
        
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(date);//设置当前日期

      return sdf.parse(sdf.format(calendar.getTime()));
  } 
    
    public static Date addEightHour(Date date)
    {
        if(date == null)
        {
            return date;
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.add(Calendar.HOUR, 8);
        return ca.getTime();
    }
    
  public static int getCurrentTimeMillis() {
    java.util.Date date = new java.util.Date();
    long temp = date.getTime();
    int result = Integer.parseInt(String.valueOf(temp).substring(0,10));

 return result;
}  


    public static void main(String[] args)  {
//       DateHelper dh = new DateHelper();
//       dh.getCurrentTimeMillis();;
//       System.out.println("dh="+dh.getCurrentTimeMillis());
        System.out.println(DateHelper.getCurrentTimeMillis());
        
        System.out.println(DateHelper.getCurrentDate());

        }
    }